import {getNodeSignSet} from "../apis/supervise";
import {message} from 'antd';
import trim from 'lodash/trim';
import {WeaLocaleProvider} from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;

export const verifySupervise = (requestid, remark = '', callbackFun) => {
    if (!verifyRemark(remark)) {
        getNodeSignSet({requestid}).then((data = {}) => {
            const {isSignMustInput = '0', signMustInputTypes = []} = data;
            if (isSignMustInput == '1' || (isSignMustInput == '2' && signMustInputTypes.indexOf('supervise') > -1)) {
                message.warning(getLabel(386186, '"签字意见"未填写'), 2);
            } else {
                callbackFun();
            }
        })
    } else {
        callbackFun();
    }
}

export const verifyRemark = (remarkcontent) => {
    let hasvalue = true;
    if (remarkcontent == null) {
        hasvalue = false;
    } else {
        let _remarkcontent = remarkcontent;
        _remarkcontent = _remarkcontent.replace(/<p>/ig, '').replace(/<\/p>/ig, '').replace(/ /ig, "").replace(/&nbsp;/ig, "").replace(/<br \/>/ig, "");
        _remarkcontent = _remarkcontent.replace(/\\n/ig, "");
        if (trim(_remarkcontent).length === 0) {
            hasvalue = false;
        }
    }
    return hasvalue;
}